import { useEffect, useState } from 'react'
import axios from 'axios'

// 自定义hooks
function usePublish(publishState) {
    const [dataSource, setdataSource] = useState([])
    const { username } = JSON.parse(localStorage.getItem("token"))

    useEffect(() => {
        axios.get(`/news?author=${username}&publishState=${publishState}&_expand=category`).then(res => {
            setdataSource(res.data)
        })
    }, [username, publishState])

    return { dataSource, setdataSource }
}

export default usePublish